﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace GIFT_SHOP_MVC.Controllers
{
    public class ProductController : Controller
    {
        //
        // GET: /Product/

       Models.GiftShop_LinQDataContext data = new Models.GiftShop_LinQDataContext();

        public ActionResult Index()
        {
            ViewData["title"] = "Our Products";
            var listproduct = data.GetProduct();
            return View("ShowProduct", listproduct);
        }
        public ActionResult GetProductByIdCategory(int id)
        {
            var cate = data.TheLoais.Single(c => c.MaTheLoai == id);
            ViewData["title"] = cate.TenTheLoai;
            var listproduct = data.GetProductByIdCategory(id);
            return View("ShowProduct", listproduct);
        }

        public ActionResult Detail(int id)
        {
            var product = data.GetProductById(id);
            product.SoLuotXem++;
            data.SubmitChanges();
            return View(product);
        }

        public ActionResult Search(string query)
        {
            var listproduct = data.SanPhams.Where(p => p.TenSanPham.Contains(query));
            ViewData["title"] = "Search Result";
            return View("ShowProduct", listproduct);
        }

        public ActionResult ProductBought()
        {
            return View();
        }

        public ActionResult ShowBill()
        {
            Models.User user = (Models.User)Session["user"];
            var listBill = data.GetBill().Where(b=>b.MaKH == user.MaUser).ToList();
            return View(listBill);
        }

        public ActionResult ShowBillDetail(int id)
        {
            var listBillDetail = data.GetBillById(id);
            return View(listBillDetail);
        }
    }
}
